#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;

const int N = 2e6 + 10, INF = 0x3f3f3f3f;

int n, s;
int f[2][N];

void solve()
{
    cin >> n >> s;
    int now = 0, odd = 1;
    f[odd][1] = s;

    int ans = 0;
    for (int k = 0;k < n;k++) {
        int mx = 0, mi = INF;
        for (int i = 1;i <= (1 << k);i++) {
            int l = 2 * i - 1, r = 2 * i;
            f[now][l] = f[odd][i] / 2;
            mi = min(mi, f[now][l]);
            f[now][r] = (f[odd][i] + 1) / 2;
            mx = max(mx, f[now][r]);
        }
        ans = max(ans, mx - mi);
        swap(now, odd);
    }
    swap(now, odd);
    cout << ans << '\n';
    for (int i = 1;i <= (1 << n);i++) {
        cout << f[now][i] << ' ';
    }
}

signed main()
{
    //ios::sync_with_stdio(0);
    //cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}